const { mySet } = require('./08.集合')
// 并集
function Union(setA, setB) {
  const newObj = new mySet()
  Object.keys({ ...setA.items, ...setB.items }).map(key => {
    newObj.add(key)
  })
  return newObj
}
// 交集
function intersection(setA, setB) {
  const newSet = new mySet()
  if (setA.size() > setB.size()) {
    Object.keys(setB.items).map(key => {
      if (setA.has(key)) {
        newSet.add(key)
      }
    })
  } else {
    Object.keys(setA.items).map(key => {
      if (setB.has(key)) {
        newSet.add(key)
      }
    })
  }
  return newSet
}
// 差集
function difference(setA, setB) {
  const newObj = new mySet()
  Object.keys(setA.items).map(key => {
    if (!setB.has(key)) {
      newObj.add(key)
    }
  })
  return newObj
}
// 是否子集
function subset(setA, setB) {
  return intersection(setA, setB).size() === setA.size()
}
const s1 = new mySet()
const s2 = new mySet()
// s1.add(1)
s1.add(2)
s1.add(3)

s2.add(3)
s2.add(4)
s2.add(5)

console.log(Union(s1, s2))
console.log(intersection(s1, s2))
console.log(difference(s1, s2))
console.log(subset(s1, s2))
